<html>
<head><meta charset="utf-8"><title>Iterators, capture and RFC 2229 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html">Iterators, capture and RFC 2229</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203450830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/203450830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#203450830">(Jul 09 2020 at 22:38)</a>:</h4>
<p>The roadmap mentions <a href="https://github.com/rust-lang/rfcs/blob/master/text/2229-capture-disjoint-fields.md">this RFC</a>, and I have a question regarding the current behavior of iterators.</p>
<p>So say you have this code (this is a WIP PR of mir-opt const-prop circa April)</p>
<div class="codehilite"><pre><span></span><code><span class="c1">// Struct declaration (abridged)</span>
<span class="k">struct</span> <span class="nc">ConstPropagator</span><span class="o">&lt;</span><span class="na">&#39;mir</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">ecx</span>: <span class="nc">InterpCx</span><span class="o">&lt;</span><span class="na">&#39;mir</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="p">,</span><span class="w"> </span><span class="n">ConstPropMachine</span><span class="o">&lt;</span><span class="na">&#39;mir</span><span class="p">,</span><span class="w"> </span><span class="na">&#39;tcx</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">locals_of_current_block</span>: <span class="nc">BitSet</span><span class="o">&lt;</span><span class="n">Local</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// (...)</span>

<span class="c1">// Then, inside of a function:</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">local</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">locals_of_current_block</span><span class="p">.</span><span class="n">iter</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">       </span><span class="bp">Self</span>::<span class="n">remove_const</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">ecx</span><span class="p">,</span><span class="w"> </span><span class="n">local</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>This code would not compile, for <code>self.locals_of_current_block</code> is borrowed immutably by <code>iter()</code>, and <code>Self::remove_const</code> needs to borrow <code>self.ecx</code> mutably. This, however, doesn't make sense to me if the compiler was able to borrow disjoint fields independently of one another back then. </p>
<p>So, I'm guessing that this error has something to do with the aforementioned RFC. Is there a closure under the hood?</p>



<a name="204207155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204207155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204207155">(Jul 17 2020 at 13:44)</a>:</h4>
<p><span class="user-mention" data-user-id="212698">@Félix Fischer</span> this actually doesn't have anything to do with RFC 2229, there is no closure  here</p>



<a name="204207171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204207171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204207171">(Jul 17 2020 at 13:44)</a>:</h4>
<p>also, I would expect this to type-check</p>



<a name="204207215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204207215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204207215">(Jul 17 2020 at 13:45)</a>:</h4>
<p>that is, I do not expect a borrow-checker error, based on what I see in this snippet alone</p>



<a name="204242715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242715">(Jul 17 2020 at 18:38)</a>:</h4>
<p>Really?? Oh noes. I wish I had known this back then. I could've made a copy of the error. I remember it as being a borrow-checker error.</p>



<a name="204242792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242792">(Jul 17 2020 at 18:39)</a>:</h4>
<p>I mean you probably were getting a borrow check error, it's just that it was probably due to some other code, or perhaps you didn't quite describe it correctly in your snippet</p>



<a name="204242823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242823">(Jul 17 2020 at 18:39)</a>:</h4>
<p>Yes, I think that's it</p>



<a name="204242825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242825">(Jul 17 2020 at 18:39)</a>:</h4>
<p>e.g., maybe you had <code>self.iter_locals_of_current_block()</code> or something?</p>



<a name="204242881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242881">(Jul 17 2020 at 18:40)</a>:</h4>
<p>basically I would guess that something was borrowing <code>self</code> as a whole</p>



<a name="204242899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242899">(Jul 17 2020 at 18:40)</a>:</h4>
<p>Yes</p>



<a name="204242909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242909">(Jul 17 2020 at 18:40)</a>:</h4>
<p>Yes, that was it</p>



<a name="204242914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242914">(Jul 17 2020 at 18:40)</a>:</h4>
<p>Un</p>



<a name="204242919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242919">(Jul 17 2020 at 18:40)</a>:</h4>
<p>Um</p>



<a name="204242925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242925">(Jul 17 2020 at 18:40)</a>:</h4>
<p>It was</p>



<a name="204242940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242940">(Jul 17 2020 at 18:40)</a>:</h4>
<p>in any case, I think the next improvement after closures (and perhaps polonius...) would likely be to try and have some way for methods to declare the fields they actually use</p>



<a name="204242948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242948">(Jul 17 2020 at 18:40)</a>:</h4>
<p><code>self.remove_const(local)</code></p>



<a name="204242949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242949">(Jul 17 2020 at 18:40)</a>:</h4>
<p>I don't quite know what it looks like</p>



<a name="204242964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204242964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204242964">(Jul 17 2020 at 18:40)</a>:</h4>
<p>but it's a common ergonomic pain point for sure</p>



<a name="204243010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243010">(Jul 17 2020 at 18:41)</a>:</h4>
<p>in my ideal world we might even be able to infer it... but ...</p>



<a name="204243018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243018">(Jul 17 2020 at 18:41)</a>:</h4>
<p>And that borrowed self mutably</p>



<a name="204243153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243153">(Jul 17 2020 at 18:42)</a>:</h4>
<p>(Even tho internally it didn't have any conflict, because it mutated only <code>ecx</code>)</p>



<a name="204243228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243228">(Jul 17 2020 at 18:42)</a>:</h4>
<p>Oh, being able to declare which fields you use would be so nice</p>



<a name="204243253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243253">(Jul 17 2020 at 18:43)</a>:</h4>
<p>I mean being able to infer it would be nicer</p>



<a name="204243335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243335">(Jul 17 2020 at 18:43)</a>:</h4>
<p>But that feels to me like it would require some serious effort</p>



<a name="204243453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243453">(Jul 17 2020 at 18:44)</a>:</h4>
<p>Now, would the compiler be able to... check if you're using only the fields that you say you're using?</p>



<a name="204243552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204243552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204243552">(Jul 17 2020 at 18:45)</a>:</h4>
<p>Ideally I'd want that to error if I'm using more than I say I do, if that makes sense</p>



<a name="204255962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204255962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204255962">(Jul 17 2020 at 20:35)</a>:</h4>
<p><span class="user-mention" data-user-id="212698">@Félix Fischer</span> yes I imagine such checking would be necessary for soundness of the feature.</p>



<a name="204256557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256557">(Jul 17 2020 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> do you reckon that such checking is possible? I don't know how to weigh the difficulty of it. It must be, right?</p>



<a name="204256703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256703">(Jul 17 2020 at 20:43)</a>:</h4>
<p>It depends on what your expectations are for such a feature</p>



<a name="204256809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256809">(Jul 17 2020 at 20:44)</a>:</h4>
<p>e.g. if a method <code>m</code> calls a method <code>p</code></p>



<a name="204256850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256850">(Jul 17 2020 at 20:44)</a>:</h4>
<p>and <code>m</code> states that it uses (only) fields <code>self.f</code> and <code>self.g</code> (of <code>self</code>, that is)</p>



<a name="204256862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256862">(Jul 17 2020 at 20:44)</a>:</h4>
<p>and <code>p</code> has no declaration in place</p>



<a name="204256875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256875">(Jul 17 2020 at 20:45)</a>:</h4>
<p>should that be rejected?</p>



<a name="204256936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256936">(Jul 17 2020 at 20:45)</a>:</h4>
<p>personally I suspect that if we made significant progress on declared fields we might want to revisit the "fields in traits" RFC, as that would pretty closely match possible functionality</p>



<a name="204256938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204256938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204256938">(Jul 17 2020 at 20:45)</a>:</h4>
<p>If you look at how we handle type-checking elsewhere, we tend to require callees to declare such things up front</p>



<a name="204257050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204257050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204257050">(Jul 17 2020 at 20:46)</a>:</h4>
<p><span class="user-mention" data-user-id="212698">@Félix Fischer</span> so I guess my answer is: I don't think it would be hard to implement in the compiler; the harder part is whether people will be happy about all the declarations they'd have to add in practice to use the feature.</p>



<a name="204257118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204257118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204257118">(Jul 17 2020 at 20:47)</a>:</h4>
<p>(but maybe we'd loosen our restrictions here, e.g. maybe non-<code>pub</code> methods in a crate would allow their field usage to be inferred...)</p>



<a name="204257387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204257387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204257387">(Jul 17 2020 at 20:49)</a>:</h4>
<p>That sounds like a fair compromise</p>



<a name="204257488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204257488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204257488">(Jul 17 2020 at 20:50)</a>:</h4>
<p>I guess that as the compiler got smarter, you could start omitting some of those declarations as well <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="204257519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204257519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204257519">(Jul 17 2020 at 20:50)</a>:</h4>
<p>Well I mean, if it ever got that far</p>



<a name="204297003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204297003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204297003">(Jul 18 2020 at 11:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <br>
hey! could you explain what the ergonomic issues are? I am not sure I get it and curious - thanks</p>



<a name="204297104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204297104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204297104">(Jul 18 2020 at 11:34)</a>:</h4>
<p>to determine, on say: <code>&amp;mut self</code> that not the entire struct needs to be mutable but only part of it based on actual accesses, and then ease the borrow checker rules?</p>



<a name="204297326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204297326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204297326">(Jul 18 2020 at 11:41)</a>:</h4>
<p>like <code>&amp;mut self::(field1, field2, field3)</code> or something?</p>



<a name="204298405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204298405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204298405">(Jul 18 2020 at 12:16)</a>:</h4>
<p>I think my suggested syntax was <code>self: &amp;mut Self { a, b, c }</code> or similar (i.e. have a syntax for refining a struct type by which fields are available, which would be related by subtyping etc.) but that's mostly bikeshedding</p>



<a name="204308718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204308718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204308718">(Jul 18 2020 at 17:06)</a>:</h4>
<p>{ } is quite good actually! But that makes it a dedicated type?</p>



<a name="204324197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204324197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204324197">(Jul 19 2020 at 00:25)</a>:</h4>
<p><span class="user-mention" data-user-id="214522">@Leo Le Bouter</span> the information has to be in the type anyway in order for it to correctly propagate and get checked</p>



<a name="204324242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204324242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204324242">(Jul 19 2020 at 00:26)</a>:</h4>
<p>otherwise maybe you managed to limit field access but e.g. you could still pass that <code>self</code> to a function that expects a whole <code>&amp;mut Foo</code></p>



<a name="204324246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204324246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204324246">(Jul 19 2020 at 00:26)</a>:</h4>
<p>it requires far too many special-cases if not done through the typesystem</p>



<a name="204369939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/204369939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#204369939">(Jul 19 2020 at 20:41)</a>:</h4>
<p>I'm not saying it's a bad thing, just interesting!</p>



<a name="205964374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/205964374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#205964374">(Aug 04 2020 at 21:40)</a>:</h4>
<p>yeah, it does really want to be part of the type</p>



<a name="205964392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/205964392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#205964392">(Aug 04 2020 at 21:40)</a>:</h4>
<p>though egads</p>



<a name="205964394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/205964394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#205964394">(Aug 04 2020 at 21:40)</a>:</h4>
<p>:)</p>



<a name="205964406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Iterators%2C%20capture%20and%20RFC%202229/near/205964406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Iterators.2C.20capture.20and.20RFC.202229.html#205964406">(Aug 04 2020 at 21:40)</a>:</h4>
<p>but maybe we can add some inference in the future, we should enable it to begin with</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>